package cn.ecut.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/testCookie")
public class CreateCookie extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 创建一个Cookie
        Cookie cookie = new Cookie("username" , "zhangsanfeng") ;
        // 设置Cookie 的存活时间
        cookie.setMaxAge( 60 * 60 * 24 * 7 );
        // 剩余的方法，自行尝试。
        // 将 Cookie 添加到 响应中
        response.addCookie( cookie );
    }
}
